package com.qdlc.p2p.biz.log.score.login;

import com.qdlc.p2p.biz.log.score.BaseTenderScoreLog;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.ScoreTemplateConstant;
import com.qdlc.p2p.common.exception.ScoreException;

/**
 * 用户注册积分
 * @author zhangyz
 */
public class RegisteScoreLog extends BaseTenderScoreLog {
    
    private static final long serialVersionUID = 1L;

    private String logTemplateNid = ScoreTemplateConstant.SCORE_USER_REGISTER;
    
    public RegisteScoreLog() {
        super();
    }

    public RegisteScoreLog(long scoreId,long userId) {
        super(userId, 0, ScoreTemplateConstant.SCORE_USER_REGISTER);
        int score = this.getScoreValue(logTemplateNid);
        this.setScore(score);
        Global.setTransfer("score", score);
        Global.setTransfer("scoreId", scoreId);
        this.setLogTemplateNid(logTemplateNid);
    }

    @Override
    public void modifyScore() {
        long scoreId = (Long)Global.getTransfer().get("scoreId");
        Boolean result = scoreDao.updateScoreById(scoreId, this.getScore(), this.getScore(), 0, 0);
        if(!result){
            throw new ScoreException("更新用户积分失败！", 1);
        }
    }
}
